package com.kangye.exam.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.kangye.exam.bean.StudentPaper;
import com.kangye.exam.service.TeacherPaperService;
import com.kangye.exam.utils.JsonFileUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.jfunc.json.JsonArray;
import top.jfunc.json.JsonObject;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/teacherPaper")
public class TeacherPaperController {
    @Resource
    private TeacherPaperService teacherPaperService;
    @RequestMapping(value = "/stupaperfind",params = {"teacherId"})//查看所有学生提交的试卷
    public Object stupaperfind(Integer teacherId,Integer pageNum, Integer pageSize){
        PageInfo pageInfo = teacherPaperService.stupaperfind(teacherId,pageNum,pageSize);
        Map<String,Object> map = new HashMap<>();
        map.put("data",pageInfo.getList());
        return map;
    }
    @RequestMapping("/pigai")
    public Object pigai(Integer studentPaperId,String studentName) throws Exception {
        String path = teacherPaperService.selectpath(studentPaperId);
        String answer = teacherPaperService.jiexi(path);
        Map<String,Object> map = teacherPaperService.socre(answer,studentName);
        return map;
    }
    @RequestMapping("/pigaisuccess")
    public Object pigaisuccess(String items,Integer studentId,String studentName,Integer score,Integer score2,Integer teacherId,Integer paperId) throws Exception{
        String Name = studentName+paperId;
        JsonFileUtil jsonFileUtil = new JsonFileUtil();
        String paperPath=jsonFileUtil.writeLocalJson(Name, items);
        teacherPaperService.insertteacer(studentId,score,score2,teacherId,paperId,paperPath);
        return null;
    }
    @RequestMapping("/selsocre")
    public Object selscore(String studentName,String pageName,Integer pageNum,Integer pageSize){
        PageInfo pageInfo = teacherPaperService.selscore(studentName, pageName, pageNum, pageSize);
        Map<String,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("data",pageInfo.getList());
        return map;
    }

}
